<template>
  <div class="header-form">
    <el-form :model="form" label-width="auto" :inline="true" ref="formref" >
      <template v-for="(item, index) in headerform" :key="index">
        <el-form-item v-if="item.type === 'input'" :label="item.label" :prop="item.prop">
          <el-input v-model="form[item.prop]"  :placeholder="item.placeholder" />
        </el-form-item>
      </template>
    
      <el-form-item>
        <el-button type="primary" @click="onSubmit">搜索</el-button>
        <el-button @click="onCancel">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script  setup>
import { cloneDeep } from 'lodash'
const form = ref({
})
const formref = ref(null)
const emit = defineEmits(['emitSubmit','resetform'])
const props=defineProps({
  formcolumns:{
    type:Array,
    default:()=>[]
  },
  headerform:{
    type:Object,
    default:()=>{}
  },

})
const onSubmit = () => {

emit('emitSubmit',form.value)
}
const onCancel = () => {
  formref.value.resetFields()
  emit('resetform',{})
}
watch(()=>props.headerform,(newdate,olddate)=>{
  form.value = cloneDeep(newdate)
})

</script>

<style lang="less" scoped>

</style>